﻿using AspNetCore.Host.Hosting;
using AspNetCore.Host.Routing;

namespace Microsoft.Extensions.DependencyInjection
{
    public interface IEndpointRouteBuilder
    {
        EndpointDataSource? EndpointDataSource { get; }
        void Map(string pathMatch, RequestDelegate requst);
    }
    public static class IEndpointRouteBuilderExtensions
    {
        public static void MapGet(this IEndpointRouteBuilder endpoints, string pathMatch, RequestDelegate requst)
        {
            var endpoint = new Endpoint(requst);
            endpoint.Metadata.Add(new HttpGetAttribute(pathMatch));
            endpoints.EndpointDataSource?.SetEndpoint(endpoint);
        }
        public static void MapPost(this IEndpointRouteBuilder endpoints, string pathMatch, RequestDelegate requst)
        {
            var endpoint = new Endpoint(requst);
            endpoint.Metadata.Add(new HttpPostAttribute(pathMatch));
            endpoints.EndpointDataSource?.SetEndpoint(endpoint);
        }
    }
}
